/*
	YoghurtGum - 2D Game Engine

	Copyright 2009-2011 Quinten Lansu
	
	Licensed under the Apache License, Version 2.0 (the "License"); you may not 
	use this file except in compliance with the License. You may obtain a copy 
	of the License at 
		
		http://www.apache.org/licenses/LICENSE-2.0 
		
	Unless required by applicable law or agreed to in writing, software 
	distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
	License for the specific language governing permissions and limitations 
	under the License. 
*/

#ifndef _YGVEC2_H_
#define _YGVEC2_H_

#include "YGSettings.h"
#include "YGGeneralMath.h"

namespace YoghurtGum
{

	class Vec2
	{

	public:

		Vec2()
		{
			Clear();
		}

		Vec2 (float a_X, float a_Y)
		{
			x = a_X;
			y = a_Y;
		}

		inline Vec2& operator = (Vec2 a_Other)
		{
			x = a_Other.x;
			y = a_Other.y;
			return *this;
		}

		inline Vec2& operator *= (Vec2& a_Other)
		{
			x *= a_Other.x;
			y *= a_Other.y;
			return *this;
		}
		inline Vec2& operator *= (float a_Scalar)
		{
			x *= a_Scalar;
			y *= a_Scalar;
			return *this;
		}
		inline Vec2 operator * (float a_Scalar)
		{
			Vec2 result(x, y);
			result *= a_Scalar;
			return result;
		}

		inline Vec2& operator -= (Vec2& a_Other)
		{
			x -= a_Other.x;
			y -= a_Other.y;
			return *this;
		}
		inline Vec2 operator - (Vec2& a_Other)
		{
			Vec2 result(x, y);
			result -= a_Other;
			return result;
		}

		inline Vec2& Clear()
		{
			x = y = 0.f;
			return *this;
		}

		inline float GetSquaredLength()
		{
			return (x * x + y * y);
		}

		inline float GetLength()
		{
			return (sqrtf(GetSquaredLength()));
		}

		inline Vec2& Normalize()
		{
			const float length = 1 / GetLength();
			x *= length;
			y *= length;
			return *this;
		}

		inline float DotProduct(Vec2& a_Other)
		{
			return ((x * a_Other.x) + (y * a_Other.y));
		}

		float x, y;	
	};
};

#endif
